<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Class_model extends AppModel {
    var $_tablename = COURSE_INSTANCE;
    var $_primary_key = COURSE_INSTANCE_CLASS_ID;
    var $_sort = NULL;
    var $_sorttype = 'ASC';
    public function Class_model(){
        parent::AppModel();
    }
    
 
    function get($class_id){
        $this->db->where(COURSE_INSTANCE_CLASS_ID, $class_id);
        $this->db->where(COURSE_INSTANCE_FRANCHISE_ID, $this->admin_id);
        $res = $this->db->get($this->_tablename);
        if($res->num_rows() > 0)
            return $res->row();
        return FALSE;
    }
	function getdetail($class_id){
        $this->db->select('p.'.PRODUCT_PRODUCT_ID.' AS product_id');
        $this->db->select('p.'.PRODUCT_NAME.' AS course');
		$this->db->select('l.'.LOCATION_NAME.' AS location_name');
        $this->db->select('c.'.COURSE_INSTANCE_START_DATE.' AS start_date');
        $this->db->select('c.'.COURSE_INSTANCE_END_DATE.' AS end_date');
        $this->db->select('c.'.COURSE_INSTANCE_DAY.' AS day');
        $this->db->select('c.'.COURSE_INSTANCE_START_TIME.' AS start_time');
        $this->db->select('c.'.COURSE_INSTANCE_END_TIME.' AS end_time');
        $this->db->select('c.'.COURSE_INSTANCE_STATUS.' AS status');
        
        $this->db->from($this->_tablename.' c');
        
        $this->db->join(PRODUCT.' p', 'c.'.COURSE_INSTANCE_PRODUCT_ID.' = p.'.PRODUCT_PRODUCT_ID.' AND c.'.COURSE_INSTANCE_FRANCHISE_ID.' = p.'.PRODUCT_FRANCHISE_ID);     
		$this->db->join(LOCATION.' l', 'c.'.COURSE_INSTANCE_LOCATION_ID.' = l.'.LOCATION_LOCATION_ID.' AND l.'.LOCATION_FRANCHISE_ID.' = c.'.COURSE_INSTANCE_FRANCHISE_ID);     
       
        
        $this->db->where('c.'.COURSE_INSTANCE_CLASS_ID, $class_id);
        $this->db->where('c.'.COURSE_INSTANCE_FRANCHISE_ID, $this->admin_id);
        $res = $this->db->get($this->_tablename);
        if($res->num_rows() > 0)
            return $res->row();
        return FALSE;
    }
    
}
?>